﻿using System.ComponentModel;
using System.Xml.Serialization;
using T4UtilityBelt.Serializers;
using T4UtilityBelt.UxDesigns;
using T4UtilityBelt.UxDesigns.Controls;

namespace T4UtilityBelt.DataDesigns
{
    public class StringProperty : Property
    {
        private const string DefaultType = "string";

        public StringProperty()
            : base(DefaultType)
        { }

        public StringProperty(string name)
            : base(DefaultType, name)
        { }

        public StringProperty(string name, bool required)
            : base(DefaultType, name, required)
        { }

        [XmlAttribute]
        [DefaultValue(0)]
        public int MaxLength { get; set; }

        public override string GetSqlType()
        {
            if (MaxLength == 0)
                return "NVARCHAR(MAX)";
            return string.Format("NVARCHAR({0})", MaxLength);
        }

        public override UxDesigns.Control CreateControl()
        {
            return new StringControl(this);
        }

        [XIgnore()]
        public override bool IsPropertyTypeSpecified
        {
            get
            {
                return DefaultType != PropertyType;
            }
        }

    }
}